package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.system.domain.LRegion;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LPaymethod;
import com.ruoyi.system.service.ILPaymethodService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付Controller
 *
 * @author zyb
 * @date 2022-01-02
 */
@RestController
@RequestMapping("/system/paymethod")
public class LPaymethodController extends BaseController
{
    @Autowired
    private ILPaymethodService lPaymethodService;
    @Autowired
    private RedisCache redisCache;

    /**
     * 查询支付列表
     */
    @PreAuthorize("@ss.hasPermi('system:paymethod:list')")
    @GetMapping("/list")
    public TableDataInfo list(LPaymethod lPaymethod)
    {
        startPage();
        List<LPaymethod> list = lPaymethodService.selectLPaymethodList(lPaymethod);
        return getDataTable(list);
    }

    /**
     * 导出支付列表
     */
    @PreAuthorize("@ss.hasPermi('system:paymethod:export')")
    @Log(title = "支付", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LPaymethod lPaymethod)
    {
        List<LPaymethod> list = lPaymethodService.selectLPaymethodList(lPaymethod);
        ExcelUtil<LPaymethod> util = new ExcelUtil<LPaymethod>(LPaymethod.class);
        util.exportExcel(response, list, "支付数据");
    }

    /**
     * 获取支付详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:paymethod:query')")
    @GetMapping(value = "/{payid}")
    public AjaxResult getInfo(@PathVariable("payid") Long payid)
    {
        return AjaxResult.success(lPaymethodService.selectLPaymethodByPayid(payid));
    }

    /**
     * 新增支付
     */
    @PreAuthorize("@ss.hasPermi('system:paymethod:add')")
    @Log(title = "支付", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LPaymethod lPaymethod)
    {
        redisCache.deleteObject("lPaymethod");
        return toAjax(lPaymethodService.insertLPaymethod(lPaymethod));
    }

    /**
     * 修改支付
     */
    @PreAuthorize("@ss.hasPermi('system:paymethod:edit')")
    @Log(title = "支付", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LPaymethod lPaymethod)
    {
        redisCache.deleteObject("lPaymethod");
        return toAjax(lPaymethodService.updateLPaymethod(lPaymethod));
    }

    /**
     * 删除支付
     */
    @PreAuthorize("@ss.hasPermi('system:paymethod:remove')")
    @Log(title = "支付", businessType = BusinessType.DELETE)
	@DeleteMapping("/{payids}")
    public AjaxResult remove(@PathVariable Long[] payids)
    {
        redisCache.deleteObject("lPaymethod");
        return toAjax(lPaymethodService.deleteLPaymethodByPayids(payids));
    }

    @GetMapping("/list/all")
    public AjaxResult listAll()
    {
        List<LPaymethod> list = redisCache.getCacheList("lPaymethod");
        if(list.size()==0){
           LPaymethod lPaymethod= new LPaymethod();
            list = lPaymethodService.selectLPaymethodList(lPaymethod);
            redisCache.setCacheList("lPaymethod",list);
        }
        return AjaxResult.success(list);
    }
}
